package com.hmall.search.web;

import com.hmall.common.PageBean;
import com.hmall.item.pojo.Item;
import com.hmall.search.dto.SearchDto;
import com.hmall.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author mengjie
 */
@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private SearchService searchService;

    // es查询商品信息
    @PostMapping("/list")
    public PageBean<Item> searchItems(@RequestBody SearchDto searchDto) throws IOException {
        // 调用ES服务查询商品信息
        return searchService.search(searchDto);
    }

    //同步ES商品信息
    @GetMapping("/mysql2ES")
    public void syncItems() throws IOException {
        // 调用ES服务查询商品信息
        searchService.mysql2ES();
    }

    //ES自动补全
    // @GetMapping("/suggestion")
    // public List<String> auto(@RequestParam String key) throws IOException {
    //     // 调用ES服务自动补全
    //     return searchService.auto(key);
    // }
}
